package swing.table;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

@SuppressWarnings("serial")
public class MyTableModel extends DefaultTableModel {
	private String[] readOnlyColumns;
	private String[] booleanColumns;
	
	public MyTableModel(Object[][] data, String[] columns,String[] readOnlyColumns,String[] booleanColumns) {
		super(data, columns);
		this.readOnlyColumns = readOnlyColumns;
		this.booleanColumns  = booleanColumns;
	}
	
	public MyTableModel(Vector data, Vector columns) {
		super(data, columns);
	}
	public MyTableModel(Object[][] data, String[] columns) {
		super(data, columns);
	}
	
	public boolean isCellEditable(int row, int columnIndex) {
		if(readOnlyColumns!=null&&readOnlyColumns.length>0){
			for(String c: readOnlyColumns){
				if(findColumn(c)==columnIndex)return false;
			}
		}
		return true;
	}
	
	public Class<?> getColumnClass(int columnIndex) {
		if(booleanColumns!=null&&booleanColumns.length>0){
			for(String c: booleanColumns){
				if(findColumn(c)==columnIndex)return Boolean.class;
			}
		}
		
		return Object.class;
	}

}
